package club.monkeywood.course.filter;

import club.monkeywood.thrift.user.dto.UserDTO;
import club.monkeywood.user.client.LoginFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class CourseFilter extends LoginFilter {

    @Value("${user.edge.service.address}")
    private String userEdgeServiceAddr;

    @Override
    protected String userEdgeServiceAddr() {
        return userEdgeServiceAddr;
    }

    //将从user-edge-service拿到的用户存入session
    //方便业务代码拿用户信息
    //缺点：集群环境下，session无法共享
    //推荐将用户信息存入redis，通过redis集群共享用户信息
    @Override
    protected void login(HttpServletRequest request, HttpServletResponse response, UserDTO userDTO) {

        request.setAttribute("user", userDTO);
    }
}

